<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon-item" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~scss/mixins.scss";

/* .icons{
  display: flex;
  flex-wrap: wrap;
  overflow: hidden;
  height: 188px;
  margin-top: 0.1rem;
  .icon-item{
    height: 50%;
    width: 25%;
    .icon-img{
      width: 100%;
      height: 80%;
      vertical-align: middle;
      text-align: center;
      .icon-img-content{
        width: 60%;
        height: 70%;
      }
    }
    .icon-desc{
      width: 100%;
      text-align: center;
    }
  }
} */

.icons {
  overflow: hidden;
  height: 0;
  padding-bottom: 50%;
  margin-top: 0.1rem;
  .icon-item {
    position: relative;
    float: left;
    height: 0;
    width: 25%;
    padding-bottom: 25%;
    .icon-img {
      position: absolute;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0.44rem;
      box-sizing: border-box;
      padding: 0.1rem;
      .icon-img-content {
        display: block;
        height: 100%;
        margin: 0 auto;
      }
    }
    .icon-desc {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      height: 0.44rem;
      line-height: 0.44rem;
      text-align: center;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      color: #333;
      @include ellipsis();
    }
  }
}
</style>
